package com.qf.user.mapper;

import com.qf.user.entity.Menu;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * <p>
 * 菜单管理 Mapper 接口
 * </p>
 *
 * @author yxh
 * @since 2023-10-29
 */
public interface MenuMapper extends BaseMapper<Menu> {

    @Select("SELECT qf_menu.name FROM qf_user_role\n" +
            "LEFT JOIN qf_role_menu ON qf_role_menu.role_id = qf_user_role.role_id\n" +
            "LEFT JOIN qf_menu ON qf_menu.id = qf_role_menu.menu_id\n" +
            "WHERE qf_user_role.user_id = #{userId}")
    public List<String> findMenuById(String userId);

    @Select("select b.* from qf_menu a\n" +
            "JOIN qf_menu b on a.id = b.parent_id\n" +
            "WHERE b.parent_id = #{menuId}")
    public List<Menu> children(String menuId);

    @Select("select * from qf_menu\n" +
            "where parent_id=0")
    public List<Menu> selectMenus();
}
